package cn.edu.ctbu.login.util;

import lombok.Getter;
import lombok.Setter;

import java.lang.reflect.Field;
import java.util.Map;

@Getter
@Setter
public class Result<T>{
    private Integer code;
    private String msg;
    private T data;
    // 使用反射实现put方法
    public void put(String key, Object value) {
        try {
            Field field = this.getClass().getDeclaredField(key);
            field.setAccessible(true);
            field.set(this, value);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            throw new RuntimeException("No such field or access error", e);
        }
    }
    // 实现putAll方法
    public void putAll(Map<String, Object> map) {
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            put(entry.getKey(), entry.getValue());
        }
    }
}
